<?php
/*
 * @Author: 杨红兵 
 * @Date: 2022-08-10 09:15:49 
 * @Last Modified by: 杨红兵
 * @Last Modified time: 2022-08-10 09:21:54
 */

namespace app\libraries\utils;

class EncryptUtil
{
    /**
     * 数字符串加密
     *
     * @Author YangHB
     * @DateTime 2022-08-10 09:15:03
     *
     * @param string $identification
     * @return array
     */
    public static function encryptionNumberidentification(string $identification): array
    {
        //11位正则方式
        //$identificationNew = preg_replace('/(\d{3})\d{1, 4}(\d{4})/', '$1****$2', $identification);
        $identificationNew = substr($identification, 0, 3) . '****' . substr($identification, -4);
        return [
            $identificationNew,
            encMe($identification, str_replace('****', '*', $identificationNew)),
        ];
    }

    /**
     * 反向解密数字标识
     *
     * @Author YangHB
     * @DateTime 2022-08-10 09:15:03
     *
     * @param string $encryption
     * @param string $mobile
     * @return string
     */
    public static function decryptNumberidentification(string $encryption, string $mobile): string
    {
        preg_match("/\d{3}\*{4}\d{4}/", $mobile, $math);
        if (empty($math)) {
            return "";
        }
        return uncMe($encryption, str_replace('****', '*', $math[0]));
    }
}
